package com.ruoyi.lm.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.lm.domain.LmTimesrecord;
import com.ruoyi.lm.service.ILmTimesrecordService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 次数消费记录Controller
 * 
 * @author ruoyi
 * @date 2020-09-02
 */
@Controller
@RequestMapping("/lm/timesrecord")
public class LmTimesrecordController extends BaseController
{
    private String prefix = "lm/timesrecord";

    @Autowired
    private ILmTimesrecordService lmTimesrecordService;

    @RequiresPermissions("lm:timesrecord:view")
    @GetMapping()
    public String timesrecord()
    {
        return prefix + "/timesrecord";
    }

    /**
     * 查询次数消费记录列表
     */
    @RequiresPermissions("lm:timesrecord:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(LmTimesrecord lmTimesrecord)
    {
        startPage();
        List<LmTimesrecord> list = lmTimesrecordService.selectLmTimesrecordList(lmTimesrecord);
        return getDataTable(list);
    }

    /**
     * 导出次数消费记录列表
     */
    @RequiresPermissions("lm:timesrecord:export")
    @Log(title = "次数消费记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(LmTimesrecord lmTimesrecord)
    {
        List<LmTimesrecord> list = lmTimesrecordService.selectLmTimesrecordList(lmTimesrecord);
        ExcelUtil<LmTimesrecord> util = new ExcelUtil<LmTimesrecord>(LmTimesrecord.class);
        return util.exportExcel(list, "timesrecord");
    }

    /**
     * 新增次数消费记录
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存次数消费记录
     */
    @RequiresPermissions("lm:timesrecord:add")
    @Log(title = "次数消费记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(LmTimesrecord lmTimesrecord)
    {
        return toAjax(lmTimesrecordService.insertLmTimesrecord(lmTimesrecord));
    }

    /**
     * 修改次数消费记录
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        LmTimesrecord lmTimesrecord = lmTimesrecordService.selectLmTimesrecordById(id);
        mmap.put("lmTimesrecord", lmTimesrecord);
        return prefix + "/edit";
    }

    /**
     * 修改保存次数消费记录
     */
    @RequiresPermissions("lm:timesrecord:edit")
    @Log(title = "次数消费记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(LmTimesrecord lmTimesrecord)
    {
        return toAjax(lmTimesrecordService.updateLmTimesrecord(lmTimesrecord));
    }

    /**
     * 删除次数消费记录
     */
    @RequiresPermissions("lm:timesrecord:remove")
    @Log(title = "次数消费记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(lmTimesrecordService.deleteLmTimesrecordByIds(ids));
    }
}
